<?php
include_once 'common.inc.php';

if($operation == 'display'){
    $members = pdo_fetch("SELECT * FROM ".tablename(MODULE_PREFIX."member")." WHERE uniacid = $uniacid and uid = $uid ");
    $members['sub_nums'] = pdo_fetchcolumn("select count(1) from ".tablename(MODULE_PREFIX.'member')." where uniacid =:uniacid and parentid =:parentid ",array(':uniacid'=>$uniacid,':parentid'=>$uid));

    $rank_list = pdo_fetchall("select m.* from ".tablename(MODULE_PREFIX."member")." sm left join ".tablename("mc_members")." m on sm.uid = m.uid  where sm.uniacid = $uniacid and sm.uid = $uid order by credit1 desc limit 20 ");
    $rank_list = set_medias($rank_list,'avatar');
    
    foreach ($rank_list as $item){
        // $item['sub_nums'] = pdo_fetchcolumn("select count(*) from ".tablename(MODULE_PREFIX."log")." where uniacid = $uniacid and from_uid = ".intval($item['uid']));
        $item['sub_nums'] = pdo_fetchcolumn("select count(1) from ".tablename(MODULE_PREFIX.'member')." where uniacid =:uniacid and parentid =:parentid ",array(':uniacid'=>$uniacid,':parentid'=>$item['uid']));
    }
    
    $my_rank = pdo_fetchcolumn("select s.rownum from ( select m.uid,@rownum := @rownum + 1 as rownum from ( select uid,credit1 from ".tablename("mc_members")." where uniacid = $uniacid order by credit1 desc ) as m,(select @rownum := 0) r ) as s where uid = $uid ");
}

include $this->template('ranking');